package com.example.notelite;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import javax.sql.StatementEvent;

public class recordActivity extends AppCompatActivity {
TextView xiugai,showtime;
EditText editText1;
ImageButton backbutton;
DbRoom dbRoom;
String id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);
        initview();
        initLister();
        dbRoom=new DbRoom(this);
        Intent intent=getIntent();
        id=intent.getStringArrayExtra("id");
        if(id!=null){
            //修改记录
            xiugai.setText(R.string.heading2);
            editText1.setText(intent.getStringExtra("record"));
            showtime.setText(intent.getStringExtra("time"));
            showtime.setVisibility(View.VISIBLE);


        }else{
            //新增记录
            xiugai.setText(R.string.heading2);

        }

    }
    public void onClick(View view){
        switch (view.getId()){
            case R.id.backbutton:
                finish();
                break;
            case R.id.cancel:
                editText1.setText(" ");
            case  R.id.save:
                String note=editText1.getText().toString().trim();
                String times=Mycontun.getTime();
                //判断保存还是新建
                if(id!=null){
                    //修改后保存
                    if(note.length()>0){
                        int i=dbRoom.updateRecord(id,note,times);
                        if(i>0){
                            Toast.makeText(view.getContext(),"保存成功",Toast.LENGTH_SHORT);
                            setResult(RESULT_OK);
                            finish();
                        }
                    }else{
                        if(note.length()>0){
                            int i=dbRoom.insertRecord(,note,times);
                            if(i>0){
                                Toast.makeText(view.getContext(),"保存成功",Toast.LENGTH_SHORT);
                                setResult(RESULT_OK);
                                finish();
                            }


                    }
                }

break;
        }
    }




    }

